import *as actionTypes from './constants';
import {fromJS} from 'immutable';
import axios from 'axios';

const changeList = (data) =>({
    type:actionTypes.CHANDE_LIST,
    data:fromJS(data),
    totalPage:Math.ceil(data.length / 10)
})

export const searchFocus = () => ({
    type: actionTypes.SEARCH_FOCUS
})

export const searchBlur = () => ({
    type: actionTypes.SEARCH_BLUR
})

export const mounsEnter= () => ({
    type: actionTypes.MOUNS_ENTER
})

export const mounsLeave= () => ({
    type: actionTypes.MOUNS_LEAVE
}) 

export const changePage= (page) => ({
    type: actionTypes.CHANDE_PAGE,
    page
}) 

export const getList = () => {
    return(dispatch)=>{
        axios.get('/api/headerList.json').then((res)=>{
            const data = res.data;
            dispatch(changeList(data.data));
        }).catch(()=>{
            console.log('error')
        })
    }
}